<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item v-for="(item,index) in breadList"
                        :key="index"
                        :to="{ path: item.path }">{{item.meta.title}}</el-breadcrumb-item>
  </el-breadcrumb>
</template>
<script>
export default {
  data () {
    return {
      breadList: [] // 路由集合
    }
  },
  watch: {
    $route () {
      this.getBreadcrumb()
    }
  },
  methods: {
    isHome (route) {
      return route.name === ''
    },
    getBreadcrumb () {
      let matched = this.$route.matched
      // 如果不是首页
      if (matched[0].name && matched[0].name === 'Layout') {
        // matched = [{ path: '/', meta: { title: '首页' } }].concat(matched)
        matched = matched.splice(1, 1)
      }
      this.breadList = matched
    }
  },
  created () {
    this.getBreadcrumb()
  }
}
</script>
